package com.ingesoft.client;

import org.apache.catalina.startup.SetAllPropertiesRule;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.tab.Tab;

public class TabObjetivoGeneral extends Tab {

	private ViewController controller;
	
	private DynamicForm formObjGeneral;
	private TextAreaItem txtObjGeneral;
	private ButtonItem btnGuardar;
 
	
	public TabObjetivoGeneral(ViewController controller)
	{
		this.controller = controller;				
		
		txtObjGeneral = new TextAreaItem();	
		txtObjGeneral.setLength(500);
		txtObjGeneral.setWidth(650);
		txtObjGeneral.setHeight(200);
		txtObjGeneral.setTop(100);
		txtObjGeneral.setTitleOrientation(TitleOrientation.TOP);
		txtObjGeneral.setTitle("Objetivo General");
		btnGuardar = new ButtonItem();
		btnGuardar.setWidth(60);
		btnGuardar.setAlign(Alignment.CENTER);
		
		formObjGeneral = new DynamicForm();
		formObjGeneral.setFields(txtObjGeneral, btnGuardar);
		formObjGeneral.setAlign(Alignment.CENTER);
	    //formObjGeneral.setTop("20%");
		
	    HStack orden=new HStack();
	   
	    orden.setWidth(850);
	    orden.setHeight(550);
	    orden.addMember(formObjGeneral);
	    orden.setLayoutAlign(Alignment.CENTER);
	    orden.setLeft("25%");
	    orden.setLayoutTopMargin(40);
	    orden.setLayoutLeftMargin(100);
	    orden.setLayoutRightMargin(100);
	    
		setPane(orden);
		
		
		setTitle("Objetivo General");
		
		eventoObtenerObjGeneral();
		eventoAsignarObjGeneral();
		eventoEditarObjGeneral();
	}
	
	public void eventoObtenerObjGeneral()
	{
		String objGeneral = null;
		//controller.obtenerObjGeneral();
		
		if(objGeneral == null)
		{
			btnGuardar.setTitle("Asignar");
		}
		else
		{
			btnGuardar.setTitle("Guardar");
		}		
	}
	
	public void eventoAsignarObjGeneral()
	{
		btnGuardar.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				if(btnGuardar.getTitle().equals("Asignar"))
				{
					//controller.asignarObjGeneral(txtObjGeneral.getTitle());
				}				
			}
		});
	}
	
	public void eventoEditarObjGeneral()
	{
		btnGuardar.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				if(btnGuardar.getTitle().equals("Guardar"))
				{
					//controller.editarObjGeneral(txtObjGeneral.getTitle());
				}
			}
		});
	}
}
